package low;

import com.eclipsesource.json.JsonArray;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * 733. 图像渲染
 */
public class FloodFill {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for(int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static int[][] stringToInt2dArray(String input) {
        JsonArray jsonArray = JsonArray.readFrom(input);
        if (jsonArray.size() == 0) {
            return new int[0][0];
        }

        int[][] arr = new int[jsonArray.size()][];
        for (int i = 0; i < arr.length; i++) {
            JsonArray cols = jsonArray.get(i).asArray();
            arr[i] = stringToIntegerArray(cols.toString());
        }
        return arr;
    }

    public static String int2dArrayToString(int[][] array) {
        if (array == null) {
            return "null";
        }
        if (array.length == 0) {
            return "[]";
        }

        StringBuilder sb = new StringBuilder("[");
        for (int[] item : array) {
            sb.append(Arrays.toString(item));
            sb.append(",");
        }

        sb.setCharAt(sb.length() - 1, ']');
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[][] image = stringToInt2dArray(line);
            line = in.readLine();
            int sr = Integer.parseInt(line);
            line = in.readLine();
            int sc = Integer.parseInt(line);
            line = in.readLine();
            int newColor = Integer.parseInt(line);

            int[][] ret = floodFill(image, sr, sc, newColor);

            String out = int2dArrayToString(ret);

            System.out.print(out);
        }
    }

    static int[] mx = new int[]{-1,0,1,0};
    static int[] my = new int[]{0,-1,0,1};

    public static int[][] floodFill(int[][] image, int sr, int sc, int newColor) {
        if (image[sr][sc]!=newColor){
            int oldColor = image[sr][sc];
            dfs(image,sr,sc,oldColor,newColor);
        }
        return image;
    }

    /**
     * Deep First Search
     * @param image
     * @param sr
     * @param sc
     * @param color
     * @param newColor
     */
    public static void dfs(int[][] image, int sr, int sc, int color, int newColor){
        if (image[sr][sc]==color){
            image[sr][sc] = newColor;
            for (int i=0;i<4;i++){
                if (sr+mx[i]>=0&&sr+mx[i]<image.length&&sc+my[i]>=0&&sc+my[i]<image[0].length){
                    dfs(image,sr+mx[i],sc+my[i],color,newColor);
                }
            }
        }
    }

}
